package com.ruowei.modules.webSocket.web.rest;

import com.ruowei.modules.webSocket.domain.MessagePush;
import com.ruowei.modules.webSocket.domain.enumeration.MessageType;
import com.ruowei.modules.webSocket.domain.enumeration.ReceiverType;
import com.ruowei.modules.webSocket.domain.enumeration.SenderType;
import com.ruowei.modules.webSocket.repository.MessagePushRepository;
import com.ruowei.modules.webSocket.service.MessagePushService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * REST controller for managing {@link MessagePush}.
 */
@RestController
@RequestMapping("/api")
@Transactional
public class MessagePushResource {

    private final Logger log = LoggerFactory.getLogger(MessagePushResource.class);

    private final MessagePushRepository messagePushRepository;
    private final MessagePushService messagePushService;

    public MessagePushResource(MessagePushRepository messagePushRepository, MessagePushService messagePushService) {
        this.messagePushRepository = messagePushRepository;
        this.messagePushService = messagePushService;
    }

    @PostMapping("testPush")
    public ResponseEntity<String> testPush(String title, String content, String receiverCode,
                                           MessageType messageType, ReceiverType receiverType) {
        Map<String, String> map = new HashMap<>();
        map.put("orderCode", "订单编号");
        map.put("status", "订单状态");
        messagePushService.pushMessage(SenderType.SYSTEM, null, receiverCode, messageType, true, title, content, map, receiverType);
        return ResponseEntity.ok("推送成功");
    }
}
